﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef AbstractButton_h__
#define AbstractButton_h__

#include "Widget.h"
#include "Font.h"

namespace SkyEngine2d
{
	
	/*!
	 \brief 按钮的抽象类
	*/
	class SGE_API AbstractButton
		:public Widget
	{
		UI_CLASS(AbstractButton)
	public:
		
		virtual ~AbstractButton();
	
		bool isHovering()const;
		bool isPushed()const;
		void setPushed(bool pushed);
	
		//! 设置普通状态下的按钮展示图片
		/*!
		\param const std::wstring & file_name  图片路径
		\param Rect cap_insets 图片的可拉伸区域，参考 Scale9Image
		\return void
		*/
		void setNormalImage(const std::wstring& file_name, const Rect& cap_insets = Rect::Zero);
	
		//! 设置普通状态下的按钮展示图片
		/*!
		\param std::unique_ptr<Scale9Image>&& image 图片
		\return void
		*/
		void setNormalImage(std::unique_ptr<Scale9Image>&& image);
	
		//! 设置鼠标悬停状态下的按钮展示图片
		/*!
		\param const std::wstring & file_name  图片路径
		\param Rect cap_insets  图片的可拉伸区域，参考 Scale9Image
		\return void
		*/
		void setHoveringImage(const std::wstring& file_name, const Rect& cap_insets = Rect::Zero);
	
		//! 设置鼠标悬浮状态下的图片
		/*!
		\param std::unique_ptr<Scale9Image> & & image 图片
		\return void
		*/
		void setHoveringImage(std::unique_ptr<Scale9Image>&& image);
	
		//! 设置鼠标按下状态下的按钮展示图片
		/*!
		\param const std::wstring & file_name 图片路径
		\param Rect cap_insets 图片的可拉伸区域，参考 Scale9Image
		\return void
		*/
		void setPushedImage(const std::wstring& file_name, const Rect& cap_insets = Rect::Zero);
	
		//! 设置鼠标按下的图片
		/*!
		\param std::unique_ptr<Scale9Image> & & image  图片
		\return void
		*/
		void setPushedImage(std::unique_ptr<Scale9Image>&& image);
	
		//! 设置按钮禁用状态下的展示图片
		/*!
		\param const std::wstring & file_name 图片路径
		\param Rect cap_insets 图片的可拉伸区域，参考 Scale9Image
		\return void
		*/
		void setDisableImage(const  std::wstring& file_name, const Rect& cap_insets = Rect::Zero);
	
		//! 获取按钮当前显示的文字
		/*!
		\return std::wstring
		*/
		std::wstring  getText()const;
	
		//! 设置按钮显示的文字
		/*!
		\param const std::wstring & text 按钮显示的文字
		\return void
		*/
		void setText(const std::wstring& text);
	
	protected:
	
		AbstractButton(Widget* parent);
	
	
		virtual void onMousePressEvent(EventMouse* event) override;
	
	
		virtual void onMouseReleaseEvent(EventMouse* event) override;
	
	protected:
		std::wstring			m_text;						/*!< 当前显示的文本. */
		std::unique_ptr<Text>	m_textRender;				/*!< 按钮展示的文本. */
		Scale9Image* m_currentImage;                        /*!< 当前的背景图片. */
	
	private:
	
		bool m_isPushed;
		bool m_isHovering;  
	
		virtual void onWidgetStateChange() override;
		virtual void onWidgetStyleChange() override;
		void updateStyleInfo();
	};
	
}


#endif // AbstractButton_h__
